import { sysLogin } from '@/api/user'
import { setToken, getToken, removeToken } from '@/utils/auth.js'

const state = {
  token: getToken()
}
const mutations = {
  setToken (state, value) {
    state.token = value
    // 让它存储到浏览器存储
    setToken(value)
  },
  removeToken (state) {
    state.token = null
    removeToken()
  }
}
const actions = {
  async getUserToken ({ commit }, form) {
    // 调用接口获取token
      const res = await sysLogin(form)
      commit('setToken', res)
      window.console.log('vuex---user:', res)  
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
